package com.gitee.ywj1352.netty.app;

import com.gitee.ywj1352.netty.server.anno.RpcService;
import com.gitee.ywj1352.netty.server.handler.RpcHandler;
import org.apache.commons.collections4.MapUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * @author wenjie.yang on 2019/10/23.
 */
@ComponentScan("com.gitee.ywj1352.netty")
@Configuration
public class AppConfig {
    @Bean
    public RpcHandler getRpcHandler(ApplicationContext cx){
        Map<String, Object> beansWithAnnotation = cx.getBeansWithAnnotation(RpcService.class);
        if (MapUtils.isNotEmpty(beansWithAnnotation)){
            for (Object obj : beansWithAnnotation.values()){
                System.out.println(obj.getClass());
            }
        }
        RpcHandler rpcHandler = new RpcHandler(beansWithAnnotation);
        return rpcHandler;
    }
}
